package com.kayang.wechat.service;


import com.kayang.common.HttpResilience4jCommand;
import com.kayang.common.aop.IService;
import com.kayang.common.aop.SPEnable;
import com.kayang.wechat.pojo.UserModel;
import com.kayang.wechat.pojo.WechatContext;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserService implements IService {

    @Override
    public String getBeforeSp() {
        // 参数{String json}  json请求信息，请求后包含响应。
        return "TSP_Before_UserEdit";
    }

    @Override
    public String getAfterSp() {
        // 参数{String json}   json请求信息，请求后包含响应。
        return "TSP_After_UserEdit";
    }


    @SPEnable
    public Map creatUser(UserModel userModel, WechatContext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), userModel.toMap(userModel));
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }

    @SPEnable
    public Map updateUser(UserModel userModel, WechatContext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), userModel.toMap(userModel));
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }


    @SPEnable
    public Map deleteUser(WechatContext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod());
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }

    @SPEnable
    public Map batchdeleteUser(Map useridMap, WechatContext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), useridMap);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }


    public Map getUser(WechatContext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod());
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }


}
